package com.zorn.platform.component.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Service;

import com.zorn.core.provider.ServiceSupportProvider;
import com.zorn.platform.component.service.IComponentService;
import com.zorn.platform.component.dao.ComponentDao;

@Service
public class ComponentService extends ServiceSupportProvider implements IComponentService {

	/* Fields
	================================================== */
	private ComponentDao componentDao;

	/* Methods
	================================================== */
	public List<Map<String, Object>> query(Map<String, Object> params) {
		List<Map<String, Object>> data = componentDao.query(params);

		return setQueryResult(isPaging() ? componentDao.count(params) : data.size(), data);
	}

	public int count(Map<String, Object> params) {
		return setCountResult(componentDao.count(params));
	}

	public String insert(Map<String, Object> params) {
		return setInsertResult(componentDao.insert(params), MapUtils.getString(params, "id"));
	}

	public int update(Map<String, Object> params) {
		return setUpdateResult(componentDao.update(params));
	}

	public int delete(Map<String, Object> params) {
		return setDeleteResult(componentDao.delete(params));
	}

	/* Getters & Setters
	================================================== */
	public void setComponentDao(ComponentDao componentDao) {
		this.componentDao = componentDao;
	}

}